<!-- 生产数据趋势图 -->
<script lang="ts" setup>
import MyChart from '@/components/MyChart.vue'
import { ref, watch } from 'vue'
const props = defineProps(['data'])

const options = ref({
  grid: {
    top: 12,
    bottom: 30,
    left: 160
  },
  tooltip: {
    trigger: 'axis',
    confine: true,
    axisPointer: {
      type: 'shadow',
      crossStyle: {
        color: '#999'
      }
    }
  },
  xAxis: [
    {
      type: 'value',
      // position: 'top',
      axisPointer: {
        type: 'shadow'
      },
      axisLabel: {
        color: '#ebeef5',
        fontSize: 18
      },
      axisTick: {
        show: false
      },
      axisLine: {
        show: false,
        lineStyle: {
          color: '#182758',
          width: 2
        }
      },
      splitLine: {
        show: true,
        lineStyle: {
          color: '#182758',
          width: 1
        }
      }
    }
  ],
  yAxis: [
    {
      type: 'category',
      data: [],
      // nameTextStyle: {
      //   color: '#ebeef5',
      //   fontSize: 16,
      //   align: 'right',
      //   // padding: [0, 5, 8, 0]
      // },
      axisLabel: {
        formatter: '{value}',
        color: '#ebeef5',
        fontSize: 18,
        align: 'right',
        // interval: 0, rotate: 30
      },
      axisTick: {
        show: false
      },
      axisLine: {
        show: false,
        lineStyle: {
          color: '#182758',
          width: 2
        }
      },
      
    }
  ],
  series: [
    {
      name: '',
      type: 'bar',
      label: {
        show: true,
        position: 'right',
        color: '#fff',
        fontSize: 18
      },
      barWidth: 15,
      color: '#129BFF',
      tooltip: {
        valueFormatter: function (value: any) {
          return value + ''
        }
      },
      data: [],
      itemStyle: {
        //圆角
        // borderRadius: [30, 30, 30, 30]
      }
    }
  ]
})
watch(
  () => props.data,
  (val) => {
    const { xList, yList } = val
    options.value.yAxis[0].data = xList
    options.value.series[0].data = yList
  },
  {
    deep: true, // 开启深度监听
    immediate: true // 立即触发一次（可选）
  }
)
</script>
<template>
  <MyChart height="430px" :option="options" />
</template>
